package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Images;
import com.ruoyi.system.service.IImagesService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * imagesController
 * 
 * @author ruoyi
 * @date 2024-01-05
 */
@Controller
@RequestMapping("/system/images")
public class ImagesController extends BaseController
{
    private String prefix = "system/images";

    @Autowired
    private IImagesService imagesService;

    @RequiresPermissions("system:images:view")
    @GetMapping()
    public String images()
    {
        return prefix + "/images";
    }

    /**
     * 查询images列表
     */
    @RequiresPermissions("system:images:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Images images)
    {
        startPage();
        List<Images> list = imagesService.selectImagesList(images);
        return getDataTable(list);
    }

    /**
     * 导出images列表
     */
    @RequiresPermissions("system:images:export")
    @Log(title = "images", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Images images)
    {
        List<Images> list = imagesService.selectImagesList(images);
        ExcelUtil<Images> util = new ExcelUtil<Images>(Images.class);
        return util.exportExcel(list, "images数据");
    }

    /**
     * 新增images
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存images
     */
    @RequiresPermissions("system:images:add")
    @Log(title = "images", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Images images)
    {
        return toAjax(imagesService.insertImages(images));
    }

    /**
     * 修改images
     */
    @RequiresPermissions("system:images:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Images images = imagesService.selectImagesById(id);
        mmap.put("images", images);
        return prefix + "/edit";
    }

    /**
     * 修改保存images
     */
    @RequiresPermissions("system:images:edit")
    @Log(title = "images", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Images images)
    {
        return toAjax(imagesService.updateImages(images));
    }

    /**
     * 删除images
     */
    @RequiresPermissions("system:images:remove")
    @Log(title = "images", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(imagesService.deleteImagesByIds(ids));
    }
}
